$(function (){
    let show = function(data){
        let html = ""
        $("#studentTb").html(html)
        data.forEach((student)=>{
            html += "<tr>"
            html += `<td>${student.id}</td>`
            html += `<td>${student.studentName}</td>`
            html += `<td>${student.course}</td>`
            html += `<td><button type="button" class="layui-btn layui-btn-primary layui-btn-radius layui-border-green mybuttom">删除</button></td>`
            html += "</tr>"
        })
        $("#studentTb").html(html)
    }

    $(".myinput").keydown(function(e){
        if (e.keyCode == 13){
            let name = $(".myinput").val();
            // alert(name=='')
            if (name == ''){
                $.ajax({
                    url:"/api/student/getAllStudents"
                }).done(function(data){
                    show(data)
                })
            }
            else{
                $.ajax({
                    type:"GET",
                    url:"http://localhost:8080/api/student/byName",
                    data: {
                        studentName:name
                    },
                    success: function(data){
                        show(data);
                    }
                })
            }

        }
    })
    $(".search").click(function(){
        $.ajax({
            type:"GET",
            url:"http://localhost:8080/api/student/byName",

            data: {
                studentName:name
            },
            success: function(data){
                show(data);
            }
        })
    })



})
